package cn.gson.crm.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gson.crm.model.pojo.Complain;
import cn.gson.crm.model.pojo.ComplainType;
import cn.gson.crm.model.pojo.Customerinfo;
import cn.gson.crm.model.pojo.TimeDeal;
import cn.gson.crm.model.pojoVo.LLJ_ComplainNeedDataVo;
import cn.gson.crm.model.pojoVo.LLJ_ComplainVo;
import cn.gson.crm.service.LLJ_ComplainService;

@Controller
public class LLJ_ComplainController {
	@Autowired
	private LLJ_ComplainService llj_ComplainService;

	@RequestMapping("/to_Complaint")    
	public String to_Complaint(){
		return "llj/Complaint";         
	}
	@RequestMapping("/to_CustomerInfo_Select")
	public String CustomerInfo_Select(){
		return "llj/CustomerInfo_Select";      
		
	}
	
	/* 查询所有的客户投诉信息    */
	@RequestMapping("/searchComplainAllM")
	@ResponseBody
	public Map searchComplainAllM(int page,int rows){  
		List<LLJ_ComplainVo> llj_ComplainVos=llj_ComplainService.getAllComplainVoPages(page, rows);
		long count=llj_ComplainService.count();
		Map map=new HashMap<>();
		map.put("total", count);
		map.put("rows", llj_ComplainVos);     
		return map;          
	}   
	
	
	/* 通过id查询客户投诉信息 */
	@RequestMapping("/searchComplainMessage")
	@ResponseBody   
	public LLJ_ComplainNeedDataVo searchComplainMessage(Long comId){ 
		LLJ_ComplainVo lComplainVo=llj_ComplainService.searchComplain(comId);
		LLJ_ComplainNeedDataVo CNeedDataVo=new LLJ_ComplainNeedDataVo();
		
		CNeedDataVo.setComDatetime(lComplainVo.getComDatetime());
		CNeedDataVo.setComDealProcess(lComplainVo.getComDealProcess());
		CNeedDataVo.setComDealResult(lComplainVo.getComDealResult());
		CNeedDataVo.setComDescribe(lComplainVo.getComDescribe());
		CNeedDataVo.setComFeedback(lComplainVo.getComFeedback());
		CNeedDataVo.setComFistReceiverName(lComplainVo.getComFistReceiverName());
		CNeedDataVo.setComId(lComplainVo.getComId());
		CNeedDataVo.setComPeople(lComplainVo.getComPeople());
		CNeedDataVo.setComSure(lComplainVo.getComSure()); 
		CNeedDataVo.setComTheme(lComplainVo.getComTheme());
		CNeedDataVo.setComUrgency(lComplainVo.getComUrgency());
		CNeedDataVo.setCustomerName(lComplainVo.getCustomerName());
		CNeedDataVo.setComplainId(lComplainVo.getComplainId());
		CNeedDataVo.setComplainContain(lComplainVo.getComplainContain());
		CNeedDataVo.setDealId(lComplainVo.getDealId());
		CNeedDataVo.setDealContain(lComplainVo.getGetDealContain());
		CNeedDataVo.setComRemarks(lComplainVo.getComRemarks()); 
		
		System.out.println("输出信息id："+CNeedDataVo.getComplainId());    
		System.out.println("输出信息type："+CNeedDataVo.getComplainContain());   
		
		return CNeedDataVo;                
	}
	//添加客户投诉信息
	@GetMapping("/addComplaintData")  
	@ResponseBody
	public String addComplaintData(LLJ_ComplainNeedDataVo NeedDataVo){
		System.out.println("输出添加的类别信息："+NeedDataVo.getComplainId());
		System.out.println("输出编辑的时间信息："+NeedDataVo.getDealId()); 
		   
		System.out.println(NeedDataVo.getComDealProcess());
		System.out.println(NeedDataVo.getComDealResult());
		System.out.println(NeedDataVo.getComDescribe());
		System.out.println(NeedDataVo.getComFeedback());  
		System.out.println(NeedDataVo.getComFistReceiverName());  
		System.out.println(NeedDataVo.getComId());
		System.out.println(NeedDataVo.getComPeople());
		System.out.println(NeedDataVo.getComRemarks());
		System.out.println(NeedDataVo.getComSure());
		System.out.println(NeedDataVo.getComTheme());
		System.out.println(NeedDataVo.getComUrgency());
		System.out.println(NeedDataVo.getDealContain());
		System.out.println(NeedDataVo.getComplainContain());
		System.out.println(NeedDataVo.getCustomerName());  
		
		if(llj_ComplainService.addComplaintMessage(NeedDataVo)){  
			return "success";   
		}else{   
			return "failed";      
		}
	}
	 
	/* 编辑客户投诉信息  */
	@GetMapping("/editComplainMessage")       
	@ResponseBody    
	public String editComplainMessage(LLJ_ComplainNeedDataVo NeedDataVo) throws Exception{
		return llj_ComplainService.editComplain_Service(NeedDataVo);      
	}   
	/* 删除客户投诉信息  */
	@GetMapping("/delete_Complaint")
	@ResponseBody
	public String delete_Complaint(Long comId){
		try { 
			llj_ComplainService.deleteOneData(comId);
			return "success";
		} catch (Exception e) {  
			return "failed";      
		}
	}
	
	/* 删除多条投诉记录   */
	@GetMapping("/complainDeleteMoreData")
	@ResponseBody   
	public String complainDeleteMoreData(String strIds){  
		String id[]=strIds.split(",");
		try {  
			for(int i=0;i<id.length;i++){
				Long deleteId=(long) Integer.parseInt(id[i]);
				llj_ComplainService.deleteOneData(deleteId);
			}
		} catch (Exception e) {
			return e.getMessage();
		}
		return "success";
	}    
	
	/* 通过投诉主题进行模糊查询   */
	@GetMapping("/getDataByTheme")
	@ResponseBody
	public List<Complain> getDataByTheme(String key){
		return llj_ComplainService.searchByTheme(key);   
	}
	
	/* 通过客户名字进行模糊查询    */
	@GetMapping("/getDataByName")  
	@ResponseBody  
	public List<Customerinfo> getDataByName(String key){
		System.out.println("输出--------------------------");
		System.out.println(key);  
		System.out.println("controller返回信息："+llj_ComplainService.searchByName(key));   
		return llj_ComplainService.searchByName(key);  
	}
	
	/* 查询投诉类型   */
	@RequestMapping("/searchComplainType")
	@ResponseBody
	public List<ComplainType> searchComplainType(){
		return llj_ComplainService.searchType();   
	}
	
	/*  查询投诉的时间类别   */
	@RequestMapping("/searchComplainDealTime")
	@ResponseBody
	public List<TimeDeal> searchComplainDealTime(){
		return llj_ComplainService.searchTimeDeal();       
	}
	

}
